#region Copyright
/*
Copyright Notice: 
Use of this file, in source or binary form, is subject to the terms and conditions set forth 
in the included license.txt file.
*/
#endregion

/* This is a customised template.
 * It overrides some optional methods from EntityMap to allow for testing 
 * with Mocks and fast object creation. Search for #custom# below. 
 */


namespace WebbnessCMS.Security.Models
{

	#region Using statements

	using System;
	using System.Collections;
	using System.Collections.Generic;
	using System.Data;
	using Neo.Core;
	using Expergent;
	using Expergent.Neo;
	using Castle.Components.Validator;
		using Neo.Core.Util;
		using Neo.Framework;
			
	#endregion

	#region IAuthenticatedUser

	/// <summary>
	/// Generated table specific Interface </summary>
	/// <remarks> This Interface is generated by the Neo Framework. Make changes to NeoSupport.vtl.</remarks>
	public partial interface IAuthenticatedUser
	{
			
				/// <summary>
		/// Property UserID - No Description </summary>
		/// <remarks> Database Path: WebbnessCMS.Security_Users.UserID.</remarks>
		/// <value> System.Guid. </value>
			System.Guid? UserID {get; set;}
	
					/// <summary>
		/// Property Login - No Description </summary>
		/// <remarks> Database Path: WebbnessCMS.Security_Users.Login.</remarks>
		/// <value> System.String. </value>
			System.String Login {get; set;}
	
					/// <summary>
		/// Property FirstName - No Description </summary>
		/// <remarks> Database Path: WebbnessCMS.Security_Users.FirstName.</remarks>
		/// <value> System.String. </value>
			System.String FirstName {get; set;}
	
		
		}

	#endregion

	#region AuthenticatedUser

	/// <summary>
	/// Generated table specific Base Class </summary>
	/// <remarks> This class is generated by the Neo Framework. Make changes to NeoSupport.vtl.</remarks>
	[Serializable]
	public partial class AuthenticatedUser : RulesEnabledEntityObject, IAuthenticatedUser
	{
	
			/// <summary>
		/// A collection of ${rel.ForeignEntity.ClassName} objects referencing this instance.</summary>
		/// <remarks> Objects referencing this instance.</remarks>
		public ManyToManyRelation<UsersGroup> UserGroup
		{
			get {return _UserGroup;}
		}
		
		private ManyToManyRelation<UsersGroup> _UserGroup;
		
			internal AuthenticatedUser(System.Data.DataRow aRow, Neo.Core.ObjectContext aContext) : base(aRow, aContext)
		{
					_UserGroup = new ManyToManyRelation<UsersGroup>(this, typeof(UsersToUsersGroups), "User", "UserGroup");
			}
		
				/// <summary>
		/// Property UserID - No Description </summary>
		/// <remarks> Database Path: WebbnessCMS.Security_Users.UserID.</remarks>
		/// <value> System.Guid. </value>
				public virtual System.Guid? UserID
		{
			get { object v = Row["UserID"]; return (System.Guid?)((v != DBNull.Value) ? v : null); }
				set { if (value.HasValue) Row["UserID"] = value; else Row["UserID"] = DBNull.Value; }
				}    

					/// <summary>
		/// Property Login - No Description </summary>
		/// <remarks> Database Path: WebbnessCMS.Security_Users.Login.</remarks>
		/// <value> System.String. </value>
			[ValidateNonEmpty("Login is a required field.")]
				public virtual System.String Login
		{
			get { return Row["Login"] as System.String; }
				set { Row["Login"] = (value != null) ? (object)value : (object)DBNull.Value; }
				}    

					/// <summary>
		/// Property FirstName - No Description </summary>
		/// <remarks> Database Path: WebbnessCMS.Security_Users.FirstName.</remarks>
		/// <value> System.String. </value>
			[ValidateNonEmpty("FirstName is a required field.")]
				public virtual System.String FirstName
		{
			get { return Row["FirstName"] as System.String; }
				set { Row["FirstName"] = (value != null) ? (object)value : (object)DBNull.Value; }
				}    

		
				/// <summary>
		/// Returns the value associated with the propName parameter.</summary>
		/// <remarks> You will need to cast the returned object into its native type upon return.</remarks>
		/// <param name="propName">String property name.</param>
		/// <returns> System.Object. </returns>
		public override object GetProperty(string propName)
		{
					if(propName == "UserID") 
				return UserID;
						if(propName == "Login") 
				return Login;
						if(propName == "FirstName") 
				return FirstName;
							return ExtendGetProperty(propName);
		}
		
		/// <summary>
		/// Sets the value associated with the propName parameter to the value specified.
		/// </summary>
		/// <param name="propName">String property name.</param>
		/// <param name="value">The value.</param>
		public override void SetProperty(string propName, object value)
		{
						if(propName == "UserID") 
			{
				UserID = (System.Guid?)value;
				return;
			}
								if(propName == "Login") 
			{
				Login = (System.String)value;
				return;
			}
								if(propName == "FirstName") 
			{
				FirstName = (System.String)value;
				return;
			}
							ExtendSetProperty(propName, value);
		}
		
		/// <summary>
		/// Adds a set of facts for this instance to the list.
		/// </summary>
		/// <param name="list">The list.</param>
		/// <param name="parent">The parent.</param>
		protected override void MakeFacts(List<WME> list, string parent)
		{
					list.Add(new WME(new EntityObjectTerm(this), MakePredicate(parent, "UserID"), UserID));
						list.Add(new WME(new EntityObjectTerm(this), MakePredicate(parent, "Login"), Login));
						list.Add(new WME(new EntityObjectTerm(this), MakePredicate(parent, "FirstName"), FirstName));
							ExtendMakeFacts(list, parent);
			myFactsHaveBeenAsserted = true;
		}

		/// <summary>
		/// Gets the default sort order.
		/// </summary>
		/// <value>The sort order.</value>
		public static PropertyComparer DefaultSortOrder
		{
			get
			{
					return new PropertyComparer("Login", SortDirection.Ascending);
				}    
		}

			
		/// <summary>
		/// Populates the EntityObject from the specified surrogate.
		/// </summary>
		/// <param name="surrogate">The surrogate.</param>
		public void Populate(AuthenticatedUserSurrogate surrogate)
		{
							Login = surrogate.Login;
						FirstName = surrogate.FirstName;
				}
	}

	#endregion

	#region AuthenticatedUserTemplate

	/// <summary>
	/// Generated table specific Query Template Class </summary>
	/// <remarks> A Query Template for AuthenticatedUser operations. </remarks>
	public class AuthenticatedUserTemplate : QueryTemplate
	{

		/// <summary>
		/// Constructor </summary>
		/// <remarks> Public Constructor.</remarks>
		/// <param name="anEntityMap">IEntityMap instance.</param>
		public AuthenticatedUserTemplate(IEntityMap anEntityMap) : base(anEntityMap)
		{
		}
		
				/// <summary>
		/// Property UserID - No Description </summary>
		/// <remarks> Database Path: WebbnessCMS.Security_Users.UserID.</remarks>
		/// <value> System.Guid. </value>
		public System.Guid UserID
		{
			get { return (System.Guid)QueryValues["UserID"]; }
			set { QueryValues["UserID"] = value; }
		}

					/// <summary>
		/// Property Login - No Description </summary>
		/// <remarks> Database Path: WebbnessCMS.Security_Users.Login.</remarks>
		/// <value> System.String. </value>
		public System.String Login
		{
			get { return (System.String)QueryValues["Login"]; }
			set { QueryValues["Login"] = value; }
		}

					/// <summary>
		/// Property FirstName - No Description </summary>
		/// <remarks> Database Path: WebbnessCMS.Security_Users.FirstName.</remarks>
		/// <value> System.String. </value>
		public System.String FirstName
		{
			get { return (System.String)QueryValues["FirstName"]; }
			set { QueryValues["FirstName"] = value; }
		}

				               
	}

	#endregion

	#region AuthenticatedUserFactory

	/// <summary>
	/// Factory class for the creation of AuthenticatedUser objects.</summary>
	public class AuthenticatedUserFactory : Neo.Framework.GenericObjectFactory<AuthenticatedUser>
	{

		/// <summary>
		/// Constructor requiring an ObjectContext parameter.</summary>
		/// <remarks> Main entry point for the retrieval and creation of new AuthenticatedUser objects.</remarks>
		/// <param name="context">ObjectContext.</param>
		public AuthenticatedUserFactory(ObjectContext context) : base(context, typeof(AuthenticatedUser))
		{
		}

			/// <summary>
		/// Create new AuthenticatedUser object.</summary>
		/// <remarks>IdMethod = Guid, PrimaryKeyIsForeignKey = False, RelationshipSetsForColumns = 1.</remarks>
		/// <returns> AuthenticatedUser </returns>
		public AuthenticatedUser CreateObject()
		{
			return (AuthenticatedUser)base.CreateObject(null);
		}
		
	
		/// <summary>
		/// Find a specified AuthenticatedUser object.</summary>
		/// <remarks> Requires Primary Key values and/or parent object instances.</remarks>
			/// <param name="arg0">.</param>
			/// <returns> AuthenticatedUser </returns>
		public AuthenticatedUser FindObject(System.Guid arg0)
		{
			return (AuthenticatedUser)base.FindObject(new object[] { arg0 } );
		}

		///<summary>
		///Find a specified AuthenticatedUser object.</summary>
		///<remarks> Requires Primary Key values and/or parent object instances.</remarks>
			///<param name="arg0">.</param>
			///<returns> AuthenticatedUser </returns>
		public AuthenticatedUser FindObjectByPK( System.Guid arg0 )
		{
			return (AuthenticatedUser) base.FindObject( new object[] {  arg0 } );
		}
		
					
			///<summary>
		///Find a specified AuthenticatedUser object.</summary>
		///<remarks> Requires Primary Key values and/or parent object instances.</remarks>
			///<param name="arg0">.</param>
			///<returns> AuthenticatedUser </returns>
		public AuthenticatedUser FindObjectByPK( System.Guid? arg0 )
		{
			return (AuthenticatedUser) base.FindObject( new object[] {  arg0.Value } );
		}
			
		/// <summary>
		/// Return the correct Query Template for the AuthenticatedUser object.</summary>
		/// <remarks> A query template is used for creating SQL like queries, in a more OO fashion.</remarks>
		/// <returns> AuthenticatedUserTemplate </returns>
		public AuthenticatedUserTemplate GetQueryTemplate()
		{
			return new AuthenticatedUserTemplate(EntityMap);
		}
		
		/// <summary>
		/// SQL like query to find and return an object.</summary>
		/// <remarks> For example: ...FindFirst("TitleAuthors.(Title = {0} or Title.Publisher = {1})", title, publisher).</remarks>
		/// <param name="qualifierFormat">String.</param>
		/// <param name="parameters">params object[].</param>
		/// <returns> AuthenticatedUser. </returns>
		public override AuthenticatedUser FindFirst(string qualifierFormat, params object[] parameters)
		{
			ObjectList<AuthenticatedUser> results = FindWithLimit(1, qualifierFormat, parameters);
			return (results.Count > 0) ? results[0] : null;
		}

		/// <summary>
		/// SQL like query to find and return an object.</summary>
		/// <remarks> For example: ...FindFirst("TitleAuthors.(Title = {0} or Title.Publisher = {1})", title, publisher).</remarks>
		/// <param name="q">The Qualifier.</param>
		/// <returns>AuthenticatedUser</returns>
		public override AuthenticatedUser FindFirst(Qualifier q)
		{
			FetchSpecification f = new FetchSpecification(EntityMap, q, 1);
			ObjectList<AuthenticatedUser> result = Find(f);
			return result.Count > 0 ? result[0]: null;
		}
	}

	#endregion

	#region AuthenticatedUserEntityMap

	//  -------- Entity Map -----------------------------------------------------
	/// <summary>Creates the in memory version of the dataset for the AuthenticatedUser DOM.</summary>
	/// <remarks>Generated by Neo Framework.</remarks>
	internal class AuthenticatedUserMap : EntityMap
	{
		  /// <summary>Array of Primary Key column names.</summary>
		  /// <remarks>Primary Key columns.</remarks>
		private static readonly string[] pkcolumns = { "UserID" };
		/// <summary>Array of Database column names.</summary>
		  /// <remarks>Database column names.</remarks>
		private static readonly string[] columns = { "UserID", "Login", "FirstName" };
		/// <summary>Array of DOM object properties.</summary>
		  /// <remarks>DOM object properties.</remarks>
		private static readonly string[] attributes = { "UserID", "Login", "FirstName" };
		/// <summary>Array of Related Object names.</summary>
		  /// <remarks>Related Object names.</remarks>
		private static readonly string[] relations = { "UsersToUsersGroups" };

		private Type concreteObjectType = typeof(AuthenticatedUser);

		  /// <summary>Property ObjectType.</summary>
		  /// <remarks>Returns the DOM's Type.</remarks>
		  /// <value>System.Type.</value>
		public override System.Type ObjectType
		{
			get { return typeof(AuthenticatedUser); }
		}
	    
		/// <summary>Property ObjectType.</summary>
		  /// <remarks>Returns the DOM's Type.</remarks>
		  /// <value>System.Type.</value>
		public override System.Type ConcreteObjectType
		{
			get { return concreteObjectType; }										 /* #custom# overridden */
			set { concreteObjectType = value; Factory.AddCustomType(value, this); }  /* #custom# overridden */
		}
	    
		/// <summary>Property TableName.</summary>
		  /// <remarks>Returns database table name.</remarks>
		  /// <value>string.</value>
		public override string TableName
		{
			get { return "Security_Users"; }
		}
	    
		/// <summary>Property PrimaryKeyColumns.</summary>
		/// <remarks>Array of Primary Key column names.</remarks>
		/// <value>string[].</value>
		public override string[] PrimaryKeyColumns
		{
			get { return pkcolumns; }
		}

		/// <summary>Property Columns.</summary>
		/// <remarks>Array of Database column names.</remarks>
		/// <value>string[].</value>
		public override string[] Columns
		{
			get { return columns; }
		}

		/// <summary>Property Attributes.</summary>
		/// <remarks>Array of DOM object properties.</remarks>
		/// <value>string[].</value>
		public override string[] Attributes
		{
			get { return attributes; }
		}

		/// <summary>Property Relations.</summary>
		/// <remarks>Array of Related Object names.</remarks>
		/// <value>string[].</value>
		public override string[] Relations
		{
			get { return relations; }
		}

		/// <summary>Generates a Hashtable, keyed by Object Name, or information regarding related objects.</summary>
		/// <remarks>Related Objects.</remarks>
		/// <returns>IDictionary.</returns>
  		protected override IDictionary GetRelationInfos()
		{
    		IDictionary infos = new Hashtable(1);
	 	 			infos.Add("UsersToUsersGroups", new RelationInfo(Factory, typeof(AuthenticatedUser), typeof(UsersToUsersGroups), "UserID", "UserID"));
					return infos;    	
		}
	    
		/// <summary>Based upon the model specified Id Method, returns the proper PkInitializer.</summary>
		/// <remarks>The object used to create a new PK value.</remarks>
		/// <returns>IPkInitializer.</returns>
		public override IPkInitializer GetPkInitializer()
		{
				return new GuidPkInitializer();
			}
	    
		/// <summary>Creates a new instance of AuthenticatedUser.</summary>
		/// <remarks>Create new AuthenticatedUser.</remarks>
		/// <param name="row">DataRow.</param>
		/// <param name="context">ObjectContext.</param>
		/// <returns>IEntityObject.</returns>
		public override IEntityObject CreateInstance(DataRow row, ObjectContext context) /* #custom# overridden */
		{
			if(ConcreteObjectType != ObjectType)
				return base.CreateInstance(row, context);
			return new AuthenticatedUser(row, context);
		}
	    
		/// <summary>Generates the in memory dataset.</summary>
		/// <remarks>Called by the Factory object.</remarks>
		/// <param name="table">DataTable.</param>
		protected override void WriteBasicSchema(DataTable table)
		{
			DataColumn		c;
			
				c = table.Columns.Add("UserID", typeof(System.Guid));
					c.Unique = true;
										c = table.Columns.Add("Login", typeof(System.String));
								c = table.Columns.Add("FirstName", typeof(System.String));
								table.PrimaryKey = new DataColumn[] { table.Columns["UserID"] };
		}
		
			/// <summary>Generates the dataset relationships.</summary>
		/// <remarks>Dataset Relationships.</remarks>
		/// <param name="table">DataTable.</param>
		protected override void WriteRelations(DataTable table)
		{
			DataRelation r;
			
		 			if(table.DataSet.Relations["Security_Users*Security_UsersToUsersGroups.UserID"] == null)
			{
				r = table.DataSet.Relations.Add("Security_Users*Security_UsersToUsersGroups.UserID", 
						table.DataSet.Tables["Security_Users"].Columns["UserID"],
						table.DataSet.Tables["Security_UsersToUsersGroups"].Columns["UserID"]);
				r.ChildKeyConstraint.UpdateRule = Rule.None;
				r.ChildKeyConstraint.DeleteRule = Rule.Cascade;
			}
				}
		}

	#endregion

	#region AuthenticatedUserSurrogate

	/// <summary>Represents an entity object disconnected from the database.</summary>
	/// <remarks>
	///   <para>Database Path: WebbnessCMS.Security_Users.</para>
	/// </remarks>
	public partial class AuthenticatedUserSurrogate : EntityObjectSurrogate, IAuthenticatedUser
	{
		/// <summary>Default constructor.</summary>
		public AuthenticatedUserSurrogate()
		{
									}
	    
	    
	    
		/// <summary>
		/// Initializes a new instance of the <see cref="AuthenticatedUserSurrogate"/> class.
		/// </summary>
		/// <param name="entity">The entity.</param>
		public AuthenticatedUserSurrogate(AuthenticatedUser entity)
		{
					UserID = entity.UserID;
						Login = entity.Login;
						FirstName = entity.FirstName;
				}

	
	
		/// <summary>
		/// Updates the entity with the values contained within the surrogate.
		/// </summary>
		/// <param name="entity">The entity.</param>
		public void BindObjectInstance(AuthenticatedUser entity)
		{
							entity.Login = Login;
						entity.FirstName = FirstName;
				}

					/// <summary>
		/// Property UserID - No Description </summary>
		/// <remarks> Database Path: WebbnessCMS.Security_Users.UserID.</remarks>
		/// <value> System.Guid. </value>
			public System.Guid? UserID
		{
    		get {return _userid;}
				set {_userid = value;}
			}

		private System.Guid? _userid;
		
							/// <summary>
		/// Property Login - No Description </summary>
		/// <remarks> Database Path: WebbnessCMS.Security_Users.Login.</remarks>
		/// <value> System.String. </value>
			[ValidateNonEmpty("Login is a required field.")]
			public System.String Login
		{
    		get {return _login;}
	    		set {_login = value;}
			}

		private System.String _login;
		
							/// <summary>
		/// Property FirstName - No Description </summary>
		/// <remarks> Database Path: WebbnessCMS.Security_Users.FirstName.</remarks>
		/// <value> System.String. </value>
			[ValidateNonEmpty("FirstName is a required field.")]
			public System.String FirstName
		{
    		get {return _firstname;}
	    		set {_firstname = value;}
			}

		private System.String _firstname;
		
			
	
		/// <summary>
		/// Binds the surrogate values to the search template.
		/// </summary>
		/// <param name="emptyTemplate">The empty template.</param>
		public void BindToSearchTemplate(AuthenticatedUserTemplate emptyTemplate)
		{
			}

	}
	#endregion

}

